<?php
	ob_start();
	session_start();
	if($_SESSION['ses_level'] != 1){
		header("location:login.php");
		exit();
	}
	ob_end_flush();
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Live Chat - DASHBOAR</title>
	<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
	 
	<!-- bootstrap JavaScript -->
	<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
	<!--custom css-->
	<link rel="stylesheet" type="text/css" href="public/css/style.css">
	
<!--Client nodejs-->
		<script src="http://192.168.1.53:8001/socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
	var socket = io.connect('http://localhost:8001');

	// on connection to server, ask for user's name with an anonymous callback
	socket.on('connect', function(){
		// call the server-side function 'adduser' and send one parameter (value of prompt)
		socket.emit('adduser', prompt("What's your name?"));
	});

	// listener, whenever the server emits 'updatechat', this updates the chat body
	socket.on('updatechat', function (username, data) {
		$('#conversation').append('<b>'+username + ':</b> ' + data + '<br>');
	});

	// listener, whenever the server emits 'updaterooms', this updates the room the client is in
	socket.on('updaterooms', function(rooms, current_room) {
		$('#rooms').empty();
		$.each(rooms, function(key, value) {
			if(value == current_room){
				$('#rooms').append('<div>' + value + '</div>');
			}
			else {
				$('#rooms').append('<div><a href="#" onclick="switchRoom(\''+value+'\')">' + value + '</a></div>');
			}
		});
	});

	function switchRoom(room){
		socket.emit('switchRoom', room);
	}
	
	// on load of page
	$(function(){
		// when the client clicks SEND
		$('#datasend').click( function() {
			var message = $('#data').val();
			$('#data').val('');
			// tell server to execute 'sendchat' and send along one parameter
			socket.emit('sendchat', message);
		});

		// when the client hits ENTER on their keyboard
		$('#data').keypress(function(e) {
			if(e.which == 13) {
				$(this).blur();
				$('#datasend').focus().click();
			}
		});
	});

</script>
<!--end nodejs-->	

</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<h2>Live Chat - QUẢN LÝ</h2>
			</div>
		</div><!--/end row-->

		<div class="row">
			
			<div class="col-md-2"></div>

			<div class="col-md-8">
			<table data-toggle="table" data-url="data1.json" data-cache="false" data-height="100%" width="100%">
				<tbody>
					<tr>
						<td colspan="2">
							<div class="panel panel-primary">
								<div class="panel-heading">Chat với chúng tôi</div>
						</td>
					</tr>
							
					<tr>
							<td valign="top">
								<div class="profile">
									Thông tin người chat</br>
									Nguyễn Văn A</br>
									SDT: 012 34 783 228
								</div>
								<div class="list-customer">
									<ul class="list-group">
										<li class="list-group-item">
										<span class="badge">14</span>
										Nguyễn Văn A</li>
										<li class="list-group-item">
										<span class="badge">14</span>
										Nguyễn Văn b</li>
										<li class="list-group-item">
										<span class="badge">14</span>
										Nguyễn Văn c</li>
									</ul>
								</div>
							</td>
							<td>
								<div class="panel-body over" id="conversation">
									Nội dung chat nằm ở đây</br>
									
								</div>
								
								<div class="input-group">
									<input type="text" class="form-control" placeholder="Nhập nội dung cần gửi" id="data"></input>
									<span class="input-group-btn">
										<button class="btn btn-default" type="button" id="datasend">Send</button>
									</span>
								</div><!-- /input-group -->
							</td>
									
						</div><!--End .panel panel-primary-->
					</tr>
				</tbody>
			</table>
			</div>
			<!--end .col-md-8-->

			<div class="col-md-2"></div>

		</div><!--end row-->

		<div id="footer">
			<div class="row">
				<div class="col-md-12">
					Thực hiện bởi nhóm 11-12: gồm các thành viên:<br/>
				</div>
				
			</div>
			<div class="row">
				<div class="col-md-3"></div>
				<div class="col-md-9">
					<span class="label label-default">Nguyen van A</span>
					<span class="label label-primary">Nguyen van B</span>
					<span class="label label-success">Nguyen van C</span>
					<span class="label label-info">Nguyen van D</span>
					<span class="label label-warning">Nguyen van E</span>
					<span class="label label-danger">Nguyen van F</span>
				</div>
			</div>
		</div><!--End footer-->
	</div>
</body>
</html>